package cn.pacerx.running.db.mybatis;


import java.util.List;
import java.util.Set;

import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandlerRegistry;
import org.mybatis.spring.boot.autoconfigure.ConfigurationCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import cn.pacerx.running.db.typehandler.EnumOrdinalCustomizerTypeHandler;
import cn.pacerx.running.db.typehandler.IntegerSetTypeHandler;
import cn.pacerx.running.db.typehandler.LongSetTypeHandler;
import cn.pacerx.running.db.typehandler.StringListTypeHandler;
import cn.pacerx.running.db.typehandler.StringSetTypeHandler;

@Configuration
public class MyBatisConfig {
    @Bean
    public ConfigurationCustomizer configurationCustomizer() {
        return configuration -> {
            //在这里可以对 configuration 进行多种操作
            TypeHandlerRegistry registry = configuration.getTypeHandlerRegistry();

            registry.register(EnumOrdinalCustomizerTypeHandler.class);

            registry.register(List.class, JdbcType.VARCHAR, StringListTypeHandler.class);
            registry.register(Set.class, JdbcType.VARCHAR, StringSetTypeHandler.class);

            registry.register(Set.class, JdbcType.BIGINT, LongSetTypeHandler.class);
            registry.register(Set.class, JdbcType.INTEGER, IntegerSetTypeHandler.class);
        };
    }
}
